package com.dw.article.controller;



import com.dw.article.service.CommentUserService;
import com.dw.common.entitys.BaseResponse;
import com.dw.common.utils.ResultUtils;
import com.dw.model.article.dtos.comment.LikeCommentDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 评论用户关系表(CommentUser)表控制层
 *
 * @author makejava
 * @since 2024-10-15 09:21:20
 */
@Slf4j
@RestController
@RequestMapping("/article/comment/user")
public class CommentUserController {

    @Resource
    private CommentUserService commentUserService;

    /**
     * 点赞
     */
    @PostMapping("/like")
    public BaseResponse<Boolean> like(@RequestBody LikeCommentDTO addArticleUserDTO) {
        log.info("点赞参数:{}", addArticleUserDTO);
        commentUserService.like(addArticleUserDTO);
        return ResultUtils.success(true);
    }

    /**
     * 获取评论点赞数量
     */
    @GetMapping("/getCount")
    public BaseResponse<Integer> getCommentLikeCount(Long commentId) {
        log.info("获取评论点赞数量参数:{}", commentId);
        return ResultUtils.success(commentUserService.getCommentLikeCount(commentId));
    }

    /**
     * 查询当前用户是否点赞
     */
    @GetMapping("/isLike")
    public BaseResponse<Integer> isLike(Long commentId) {
        log.info("查询当前用户是否点赞参数:{}", commentId);
        Integer liked = commentUserService.isLike(commentId);
        return ResultUtils.success(liked);
    }

}

